package com.geezdata.cps.base.utils;

import java.lang.reflect.Type;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.Gson;
import com.google.gson.JsonIOException;

public class GsonUtil {
    private static Logger logger = LoggerFactory.getLogger(JsonUtil.class);
    private static Gson gson = new Gson();
   
    public static String toJson(Object object) {
        try {
            return gson.toJson(object);
        } catch (JsonIOException e) {
            logger.error(e.getMessage(), e);
        }
        return null;
    }

    public static <T> T fromJson(String json, Type typeOfT) {
        return gson.fromJson(json, typeOfT);
    }
}
